package com.liuyucheng.idea_springboot.statemachine;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.statemachine.StateMachine;
import org.springframework.stereotype.Service;

@Service
public class OrderService {

    @Autowired
    private StateMachine<OrderStates, OrderEvents> stateMachine;

    public void pay(String orderId) {
        System.out.println("订单 " + orderId + " 支付事件");
        stateMachine.sendEvent(OrderEvents.PAY);
    }

    public void deliver(String orderId) {
        System.out.println("订单 " + orderId + " 发货事件");
        stateMachine.sendEvent(OrderEvents.DELIVER);
    }

    public void receive(String orderId) {
        System.out.println("订单 " + orderId + " 收货事件");
        stateMachine.sendEvent(OrderEvents.RECEIVE);
    }
}